document.querySelector('#btn-login').addEventListener('click', async () => {
    const form = document.querySelector('.login-form')
    const data = serialize(form, { hash: true, empty: true })
    const { username, password } = data
    if (username.length < 5) {
      return showToast('请输入长度不小于5的用户名')
    }
    if (password.length < 5) {
      return showToast('请输入长度不小于5的密码')
    }
    try{
      const res = await axios({
        url: '/login',
        method: 'post',
        data: {
          username,
          password
        }
      })
      localStorage.setItem('token',res.data.data.token)
      localStorage.setItem('user',JSON.stringify(res.data.data))
      showToast(res.data.message)
      setTimeout(()=>{
        location.href = './index.html'
      },1000)
    }catch(err){
        showToast(err.response.message)
    }
  })
  

